package dao;

import java.sql.*;

public class AddDao {
    public boolean addDDao(String sName, int price,String date) {
        PreparedStatement preparedStatement = null;
        Connection connection = null;
        ResultSet resultSet = null;
        try {
            connection = DBConnection.getConnection();
            preparedStatement = connection.prepareStatement("select d_name from discs where d_name=?");
            preparedStatement.setString(1, sName);
            resultSet = preparedStatement.executeQuery();
            if (!resultSet.next()) {
                preparedStatement=connection.prepareStatement("insert into  discs values(?,?,?,0,1)");
                preparedStatement.setString(1,sName);
                preparedStatement.setInt(2,price);
                preparedStatement.setDate(3, Date.valueOf(date));
                preparedStatement.execute();
                return true;
            }else {
                return false;
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
            return false;
        }finally {
            DBConnection.release(connection,preparedStatement,resultSet);
        }
    }
}